#!/usr/bin/python3
"""
[python @classmethod的使用场合][01]
[01]: http://30daydo.com/article/89
"""

import sys


class Foo(object):
    def __init__(self, year=2022, month=1, day=1):
        self.day = day
        self.month = month
        self.year = year

    @classmethod
    def get_date(cls, string_date):
        print("XXXXXInput =", string_date, file=sys.stderr)
        # 第一个参数是cls，表示调用当前的类名
        year, month, day = map(int, string_date.split('-'))

        date = cls(year, month, day)
        # 返回一个初始化后的类
        return date

    def output_date(self):
        print("YYYY/MM/DD = %04d/%02d/%02d" % (self.year,
                                               self.month,
                                               self.day))


def main(argc, argv):
    print("=== A ===")
    a = Foo.get_date('2022-3-10')
    a.output_date()

    print("=== B ===")
    b = Foo(2019, 9, 1)
    b.output_date()

    return 0


if __name__ == '__main__':
    sys.exit(main(len(sys.argv), sys.argv))
